package com.topvision.bureau.view.regmode;


import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TextView;


import com.kernal.demo.plateid.R;
import com.topvision.bureau.presenter.RegModePresenter;
import com.topvision.commomsdk.TouchInterface;
import com.topvision.commomsdk.activity.BaseActivity;
import com.topvision.voicesdk.BaseVoiceActivity;
import com.topvision.voicesdk.CommonVoice;
import com.topvision.voicesdk.VoiceInterface;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindViews;
import butterknife.ButterKnife;

/**
 * 车牌识别选择模式类
 * User: jack(jackgu@topvision-cv.com)
 * Date: 2016-12-02
 * Time: 11:23
 */
public class ChooseCarModeActivity extends BaseVoiceActivity implements TouchInterface, VoiceInterface {
    //三种车牌识别模式
    @BindViews({R.id.real_time_rapid, R.id.car_take_photo})
    List<TextView> textViews;
    TextView realTimeRapid, carTakePhoto;
    int currentId = 0;
    List<Integer> viewIds;
    int indexSelected = 0;
    //默认没有进入过远程协助
    Context context;
    RegModePresenter regModePresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_choose_car_mode);
        context = this;
        ButterKnife.bind(this);
        regModePresenter = new RegModePresenter(this);
        initUi();
        initData();
        stateTag();
    }

    private void initUi() {
        realTimeRapid = textViews.get(0);
        carTakePhoto = textViews.get(1);
    }


    private void initData() {
        viewIds = new ArrayList<>();
        currentId = R.id.real_time_rapid;
        viewIds.add(R.id.real_time_rapid);
        viewIds.add(R.id.car_take_photo);
    }

    /**
     * 设置图片背景
     *
     * @author jack
     * create at 2016/11/21 10:15
     */
    private void stateTag() {
        if (currentId == R.id.real_time_rapid) {
            realTimeRapid.setTextColor(Color.BLACK);
            carTakePhoto.setTextColor(Color.WHITE);
            realTimeRapid.setSelected(true);
            carTakePhoto.setSelected(false);
        } else if (currentId == R.id.car_take_photo) {
            realTimeRapid.setTextColor(Color.WHITE);
            carTakePhoto.setTextColor(Color.BLACK);
            realTimeRapid.setSelected(false);
            carTakePhoto.setSelected(true);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        setTouchInterfaceListener(this);
        setVoiceInterfaceListener(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        setTouchInterfaceListener(null);
        setVoiceInterfaceListener(null);
    }

    @Override
    public void doForwardTouch() {
        if (indexSelected < viewIds.size() - 1) {
            indexSelected++;
            currentId = viewIds.get(indexSelected);
            stateTag();
        }
    }

    @Override
    public void doBackwardTouch() {
        if (indexSelected > 0) {
            indexSelected--;
            currentId = viewIds.get(indexSelected);
            stateTag();
        }
    }

    @Override
    public void doClickTouch() {
        if (currentId == R.id.real_time_rapid) {
            regModePresenter.jumpVideoRecog(false, ChooseCarModeActivity.this);
        } else if (currentId == R.id.car_take_photo) {
            regModePresenter.jumpTakePic(ChooseCarModeActivity.this);
        }
        // finish();
    }


    @Override
    public void doDoubleTouch() {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void dealWithVoice(String data) {
        if (data.contains("实时模式")) {
            regModePresenter.jumpVideoRecog(false, ChooseCarModeActivity.this);
        } else if (data.contains("拍照模式")) {
            regModePresenter.jumpTakePic(ChooseCarModeActivity.this);
        } else if (data.contains("返回")) {
            finish();
        }
    }
}